const createServer = require('http').createServer
const parse = require('url').parse
const WebSocketServer = require('ws').WebSocketServer

const server = createServer();

const wss1 = new WebSocketServer({noServer: true});
wss1.on('connection', function connection(ws) {
    console.log("connection", ws)
});

server.on('upgrade', function upgrade(request, socket, head) {
    const {pathname} = parse(request.url);

    if (pathname === '/websocket/http') {
        wss1.handleUpgrade(request, socket, head, function done(ws) {
            wss1.emit('connection', ws, request);
        });
    } else {
        socket.destroy();
    }
});

server.listen(8000);


module.exports = {}
